<template>
  <div class="app-container  bg-gray">
    <el-row class="box-1">
      <el-col :span="24">
        <el-card>
          <div class="header">
            <div>
              <el-input v-model="searchTerms.searchValue" placeholder="请输入内容" class="search-input" @change="getData" />
              <el-button type="success" class="do-btn" icon="el-icon-search" @click="getData">搜索</el-button>
            </div>

            <column-controller :check-items="th" style="float:right;" @change="columnCheck" />
          </div>
          <el-table v-loading="tableLoading" :data="tableData" :max-height="tableMaxHeight" border highlight-current-row @sort-change="handleSortChange">
            <el-table-column prop="id" label="ID" min-width="65" header-align="center" align="center" sortable />
            <el-table-column v-if="th[0].check" prop="member_name" label="客户名称" min-width="90" header-align="center" align="center" />
            <el-table-column v-if="th[1].check" prop="member_phone" label="客户手机" min-width="120" header-align="center" align="center" />
            <el-table-column v-if="th[2].check" prop="order_number" label="订单号" min-width="140" header-align="center" align="center" />
            <el-table-column v-if="th[3].check" prop="admin_name" label="操作人" min-width="90" header-align="center" align="center" />
            <el-table-column v-if="th[4].check" prop="goods_name" label="商品名称" min-width="130" header-align="center" align="center" />
            <el-table-column v-if="th[5].check" prop="goods_money" label="商品金额" min-width="110" header-align="center" align="center" sortable />
            <el-table-column v-if="th[6].check" prop="money" label="提成" min-width="80" header-align="center" align="center" />
            <el-table-column v-if="th[7].check" prop="cur_bonus" label="当时总提成" min-width="100" header-align="center" align="center" />
            <el-table-column v-if="th[8].check" label="类型" min-width="120" header-align="center" align="center">
              <template slot-scope="scope">
                <el-tag>{{ scope.row.type==0?'售前提成':scope.row.type==1?'售后提成':scope.row.type==2?'提现':'退款' }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column v-if="th[9].check" prop="created_at" label="记录时间" min-width="160" header-align="center" align="center" sortable />
          </el-table>
          <el-pagination
            :current-page.sync="currentPage"
            :page-size="pageSize"
            :page-sizes="pageSizes"
            :total="total"
            class="pagination"
            layout="total, sizes, prev, pager, next, jumper"
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"/>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { ColumnController } from '../components'
import { handleCurrentChange, handleSizeChange, handleSortChange, columnCheck } from '../../utils/table'
export default {
  components: { ColumnController },
  data() {
    return {
      searchTerms: {
        searchValue: ''
      },

      // 表格相关数据
      tableMaxHeight: document.documentElement.clientHeight - 280,

      // 表格相关参数
      tableLoading: false,
      currentPage: 1,
      pageSize: this.$store.getters.userInfo.pageSize,
      pageSizes: [10, 20, 50, 100, 1000],
      total: 0,
      tableData: [],
      th: [{ name: '客户名称', check: true },
        { name: '客户手机', check: true },
        { name: '订单号', check: true },
        { name: '操作人', check: true },
        { name: '商品名称', check: true },
        { name: '商品金额', check: true },
        { name: '提成', check: true },
        { name: '当时总提成', check: true },
        { name: '类型', check: true },
        { name: '记录时间', check: true }]
    }
  },
  created() {
    this.getData()
  },
  methods: {
    handleCurrentChange, handleSizeChange, handleSortChange, columnCheck,
    getData(order) {
      this.tableLoading = true
      order || (order = {})
      const url = 'finance/commossion'
      const data = {
        page_no: this.currentPage,
        page_size: this.pageSize,
        search: this.searchTerms.searchValue
      }
      order.sortName && (data.sortName = order.sortName)
      order.sortOrder && (data.sortOrder = order.sortOrder)
      this.$store.dispatch('GetConnect', { url, data }).then(res => {
        this.tableData = res.data.rows
        this.total = res.data.total
        this.tableLoading = false
      }).catch(e => {
        this.tableLoading = false
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    }
  }
}
</script>

<style lang="scss" type="text/scss" scoped>
@import '../../styles/index.scss';
.box-1 {
  .header {
    @include flex-row(center, space-between);
    padding-bottom: 15px;
    div {
      @include flex-row(center, flex-start);
      flex-wrap: wrap;
    }
    .search-input {
      width: 240px;
    }
    .do-btn {
      @extend .bg-green;
      margin-left: 6px;
    }
  }
}
</style>
